{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "41733a25-8503-4cf5-9d0a-2447840b0a03",
   "metadata": {},
   "source": [
    "Chapter 07\n",
    "# 3个字符全排列\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9a89cdc2-6062-4b20-96ff-a94630308d6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import itertools\n",
    "string = 'abc'\n",
    "perms_all = itertools.permutations(string)\n",
    "# 返回一个可迭代对象perms，其中包含了string的所有排列方式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "95edbd1c-5df3-4516-9fb4-4bcb4acf121d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc\n",
      "acb\n",
      "bac\n",
      "bca\n",
      "cab\n",
      "cba\n"
     ]
    }
   ],
   "source": [
    "# 全排列\n",
    "for perm_idx in perms_all:\n",
    "    print(''.join(perm_idx))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
